import java.util.StringTokenizer;


class P130_39643 {

	public static void main(String[] args) {
		int n, k;
		while (true) {
			StringTokenizer st = new StringTokenizer(readLn());
			
			n = Integer.parseInt(st.nextToken());
			k = Integer.parseInt(st.nextToken());
			
			if (n == 0 && k == 0) break;
			
			process(n, k);
			
		}
	}
	
	private static void process(int n, int k) {
		
//		if (n == 1) {
//			System.out.println("1");
//			return;
//		}
		
		
		
		for (int i = 0; i < n; i++) {
			int[] p = new int[n];
			
			for (int l = 0; l < p.length; l++) {
				p[l] = l+1;
			}
			
			if (getLastSurvivor(p,i,k) == 1) {
				System.out.println(i+1);
				return;
			}
			
		}
		
	}

	private static int getLastSurvivor(int[] p, int i, int k) {
		
		int start = i;
		
		int remaining = p.length;
		
//		System.out.println(Arrays.toString(p));
		
		while (remaining > 1) {
			
			for (int index = 0; index < k-1; index++) {
				
				do {
					start++;
					if (start >= p.length) {
						start = 0;
					}
				} while (p[start] == -1);
				
			}
			
			int buried = start;
			p[start] = -1;
			
			do {
				start++;
				if (start >= p.length) {
					start = 0;
				}
			} while (p[start] == -1);
			
			for (int index = 0; index < k - 1; index++) {
				
				do {
					start++;
					if (start >= p.length) {
						start = 0;
					}
				} while (p[start] == -1);
				
			}
			
			swap(p, buried, start);
			
			start = buried;
			
			do {
				start++;
				if (start >= p.length) {
					start = 0;
				}
			} while (p[start] == -1);
				
			
//			System.out.println(Arrays.toString(p));
			
			remaining--;
		}
		
		for (int index = 0; index < p.length; index++) {
			if (p[index] > -1) return p[index];
		}
		
		return -1;
	}

	private static void swap(int[] p, int buried, int start) {
		int aux = p[buried];
		p[buried] = p[start];
		p[start] = aux;
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}
	
}
